/**
 * All Rights Reserved , Copyright (C) 2023 , 青岛鼎信通讯股份有限公司
 *
 *BaseRemindConfigHistoryController
 * 提醒配置历史表
 *
 * 修改纪录
 * 2023-04-07 版本：1.0 wangxinhua 创建。
 * @version 版本：1.0
 * @author 作者：wangxinhua
 * 创建日期：2023-04-07
 */

package com.topscomm.base.controller;

import java.util.List;
import java.util.Map;

import com.topscomm.pub.util.BaseUtil;
import com.topscomm.pub.vo.Page;
import com.topscomm.pub.vo.Query;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.topscomm.base.controller.auto.BaseRemindConfigHistoryControllerAuto;
import com.topscomm.pub.util.StringBufferProxy;
import com.topscomm.pub.util.StringUtil;
import com.topscomm.pub.vo.ResponseResult;

/**
 * @author: wangxinhua
 * @date: 2023-04-07
 * @description:提醒配置历史表Controller
 * @modify:
 */
@RestController
@RequestMapping("base/remindConfigHistory")
public class BaseRemindConfigHistoryController extends BaseRemindConfigHistoryControllerAuto implements IBaseRemindConfigHistoryController {
	/**
	 * @author: wangxinhua
	 * @date: 2023-04-07
	 * @param paraMap
	 * @return
	 * @description:转换出查询SQL语句
	 * @modify:
	 */
	@Override
	protected String spellListSql(Map<String, Object> paraMap) {
		StringBufferProxy sql = new StringBufferProxy();
		sql.appendSingle(" 1=1 ");
		if (paraMap.containsKey("qry_name")) {
			String value = paraMap.get("qry_name").toString();
			if (!StringUtil.isEmpty(value))
				sql.appendSingle(" and name like '%{0}%' ", value);
		}
		if (paraMap.containsKey("qry_code")) {
			String value = paraMap.get("qry_code").toString();
			if (!StringUtil.isEmpty(value))
				sql.appendSingle(" and code = '{0}' ", value);
		}
		if (paraMap.containsKey("qry_sourcetype")) {
			String value = paraMap.get("qry_sourcetype").toString();
			if (!StringUtil.isEmpty(value))
				sql.appendSingle(" and sourcetype = '{0}' ", value);
		}
		if (paraMap.containsKey("qry_sourceid")) {
			String value = paraMap.get("qry_sourceid").toString();
			if (!StringUtil.isEmpty(value))
				sql.appendSingle(" and sourceid = '{0}' ", value);
		}
		return sql.toString();
	}

	/**
	 * @author: wangxinhua
	 * @date: 2023-04-07
	 * @param paraMap
	 * @return
	 * @description:转换出查询SQL语句
	 * @modify:
	 */
	@Override
	@GetMapping(value = "/refList")
	public ResponseResult<Object> refList(@RequestParam(required = false) Map<String, Object> paraMap) {
		return super.refList(paraMap);
	}

	/**
	 * 重写，按照id排序
	 *
	 * @description:
	 * @param paraMap
	 * @return
	 * @author: donghang
	 * @date: 2020年12月1日下午7:54:03
	 * @modify:
	 */
	@Override
	@GetMapping(value = "/list")
	public ResponseResult<Object> list(@RequestParam(required = false) Map<String, Object> paraMap) {
		try {
			paraMap = BaseUtil.decodeSecureMap(paraMap);
			Query query = new Query(paraMap);
			String sqlWhere = this.spellListSql(paraMap);
			int totalCount = this.service.getCount(sqlWhere);
			List<Map<String, Object>> tempList = null;
			if (query.getPageSize() > 0) {
				tempList = this.service.queryMapForPage(sqlWhere, query.getCurrentPage(), query.getPageSize(),
						query.getSidx(), query.getSord());
			} else {
				sqlWhere += " order by id asc";
				tempList = this.service.queryMapByWhere(sqlWhere);
			}
			// this.service.setDispFields(tempList);
			Page page = new Page(tempList, totalCount, query.getPageSize(), query.getCurrentPage());
			return ResponseResult.ok(page);
		} catch (Exception ex) {
			return handleControllerException(ex);
		}
	}
}

